/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import org.junit.Test;
import vendingmachine10.VendingMachine2;
import static org.junit.Assert.*;

/**
 *
 * @author Peach
 */
public class VendingTest2{

    VendingMachine2 testView=null;

    @Test
    public void Test_AddMoney(){
        testView =new VendingMachine2();
        
	//测试投了五角的情况
        double current=testView.getMoney();
	testView.addFiveCoin();
	assertEquals(current+0.5,testView.getMoney());
	
	//测试投了一元得情况
	current=testView.getMoney();
	testView.addOneCoin();
	assertEquals(current+1,testView.getMoney());
    }

    @Test
    public void Test_MoneyEnoughForJuice(){
        //测试当投入金额达到0.5元时〖橙汁〗按钮亮起
        testView=new VendingMachine2();
        
        testView.addFiveCoin();//投入五角
        assertEquals(testView.isCanBuyJuice(),1);
    }
        
    @Test
    public void Test_MoneyEnoughForBeer(){
        //测试当投入金额达到1.5元时〖啤酒〗按钮亮起
        testView=new VendingMachine2();
        
        testView.addFiveCoin();//投入五角
        testView.addOneCoin();//投入一元
        assertEquals(testView.isCanBuyBeer(),1);
    }
    
    @Test
    public void Test_NoProduct(){
        //若无货品，则相应按钮无法按下
        testView=new VendingMachine2();
        
        testView.setBeerCounts(0);
        testView.setJuiceCounts(0);
        assertEquals(testView.isCanBuyBeer(),0);
        assertEquals(testView.isCanBuyJuice(),0);
    }
    
    @Test
    public void Test_BuyJuice(){
        //测试投入足够钱后，按下〖橙汁〗的按钮，会送出橙汁
        testView=new VendingMachine2();
        
        testView.addFiveCoin();
        double money=testView.getMoney();
        testView.askForJuice();
        assertEquals(testView.getShopingMessage(),"一罐橙汁");
        assertEquals(testView.getMoney(),money-0.5);
    }
    
    @Test
    public void Test_BuyBeer(){
        //测试投入足够钱后，按下〖啤酒〗的按钮，会送出啤酒
        testView=new VendingMachine2();
        
        testView.addFiveCoin();
        testView.addOneCoin();
        double money=testView.getMoney();
        testView.askForBeer();
        assertEquals(testView.getShopingMessage(),"一瓶啤酒");
        assertEquals(testView.getMoney(),money-1.5);
    }
    
    @Test
    public void Test_ReturnMoney(){
        //投入一元后且按下〖退币〗的按钮，则退出所投一元钱
        testView=new VendingMachine2();
        
        testView.addOneCoin();//投入一元
        double money=testView.getMoney();
        testView.askForReturn();//按下〖退币〗的按钮
        assertEquals("1张1元,0张5角",testView.getMoneyMessage());
        assertEquals(money-1,testView.getMoney());
    }

    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
    // @Test
    // public void hello() {}

}